
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php

Class register extends MX_Controller {

    public function register_data() {
        $this->session->unset_userdata('message');
        $fname = $this->input->post('fname');
        $lname = $this->input->post('lname');
        $gender = $this->input->post('gender');
        $phone = $this->input->post('phone');
        $email = $this->input->post('email');
        $pd = $this->input->post('password');
        $this->input->post('passwordcon');
        $pdsha1 = (sha1($pd));
        $this->load->model('register_model');
        $loc1 = $this->register_model->tbl_position();
        $u = $this->input->post('text');



        foreach ($loc1->result() as $row) {
            $loc = $row->pos_id;
        }

        $this->form_validation->set_rules('text', 'Captcha', 'required');
        $this->form_validation->set_rules('fname', 'firstname', 'required|trim|alpha');
        $this->form_validation->set_rules('lname', 'lastname', 'required|trim|alpha');
        $this->form_validation->set_rules('phone', 'number', 'required|trim|integer|min_length[9]');
        $this->form_validation->set_rules('email', 'email', 'required|trim|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[8]');
        $this->form_validation->set_rules('passwordcon', 'Password', 'required|trim|matches[password]');

        if ($this->form_validation->run() == FALSE) {
            $this->load->model('captcha_model');
            $data['captcha_img'] = $this->captcha_model->captcha();
            $this->load->view('layout/site_master', $data);
        } else {
            $this->load->model("captcha_model");
            if ($this->captcha_model->login($u) > 0) {
                $this->load->model('register_model');
                /** Validate captcha */
                $this->register_model->register_data($fname, $lname, $gender, $phone, $email, $pdsha1, $loc);
//$this->load->view('layout/profile');
             redirect('authentication/register/profile');
            } else {
                $message = "Wrong Text !";
                $this->load->model('captcha_model');
                $data['captcha_img'] = $this->captcha_model->captcha();
                $this->session->set_userdata('message', $message);
                $this->load->view('layout/site_master', $data);
            }
        }
    }
    public function profile(){
        $this->load->view('layout/profile');
    }

}

?>

